//
//  STALogSetting.m
//  STALog
//
//  Created by jerry on 2019/5/5.
//  Copyright © 2019 jerry. All rights reserved.
//

#import "STALogSetting.h"
#import "STALogView.h"

void STALogNSLog(NSString *format, ...){
    va_list args;
    if (format) {
        va_start(args, format);
        NSString *message = nil;
        message = [[NSString alloc] initWithFormat:format arguments:args];
        ///时间格式化
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss [SSS]";
        message = [NSString stringWithFormat:@"%@ %@\n",[formatter stringFromDate:[NSDate new]],message];
        const char *resultCString = NULL;
        if ([message canBeConvertedToEncoding:NSUTF8StringEncoding]) {
            resultCString = [message cStringUsingEncoding:NSUTF8StringEncoding];
        }
        //控制台打印
        printf("%s", resultCString);
        [STALogView addText:message];
    }
    
}

#ifdef DEBUG

STALogLevel ogaLogLevel = STALogLevelAll;

#else

STALogLevel ogaLogLevel = STALogLevelWarn|STALogLevelError;

#endif
@implementation STALogSetting

/**
 * 设置LST水平
 * param logLevel :
 * DEBUG builds 默认 STALogLevelAll
 * RELEASE builds 默认 STALogLevelWarn 和 STALogLevelError
 */
+ (void)setLogLevel:(STALogLevel)logLevel{
    ogaLogLevel = logLevel;
}

/**
 * 展示自定义控制台
 */
+ (void)showConsoleView{
    [STALogView show];
}


@end
